package cn.wolfcode.config;

import cn.wolfcode.job.SeckillProductCacheJob;
import cn.wolfcode.util.ElasticJobUtil;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler;
import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by lanxw
 */
@Configuration
public class BusinessJobConfig {
    @Bean(initMethod = "init")
    public SpringJobScheduler seckillProductCacheJobScheduler(CoordinatorRegistryCenter rc, SeckillProductCacheJob job,
                                                     @Value("${jobCron.initSeckillProduct}") String cron) {
        LiteJobConfiguration configuration = ElasticJobUtil.createJobConfiguration(job.getClass(), cron, 3, "0=10,1=12,2=14", false);
        SpringJobScheduler scheduler = new SpringJobScheduler(job, rc, configuration);
        return scheduler;
    }
}
